<template>

  <el-form :inline="true" :model="listagency" >
    <el-form-item label="企业名称">
      <el-input v-model="listagency.name" />
    </el-form-item>
    <el-form-item label="登录账号：">
      <el-input v-model="listagency.phone" />
    </el-form-item>
    <el-form-item label="接单状态">
      <el-select
        v-model="listagency.status"
        clearable
        placeholder="请选择接单状态"
        style="width: 240px"
      >
        <el-option label="接单中" value="1"/>
        <el-option label="休息中" value="0"/>
      </el-select>
    </el-form-item>
    <el-form-item label="账号状态">
      <el-select
      v-model="listagency.status"
      clearable
      placeholder="请选择账号状态"
      style="width: 240px"
      >
      <el-option label="冻结" value="1"/>
      <el-option label="正常" value="0"/>
      </el-select>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="findall()">搜索</el-button>
    </el-form-item>
  </el-form>


<!--  列表-->
  <el-table :data="tableData" style="width: 100%">
    <el-table-column prop="id" label="序号" width="130" />
    <el-table-column prop="name" label="企业名称" width="130" />
    <el-table-column prop="phone" label="登录账号" width="130" />
<!--    <el-table-column prop="idNumber" label="统一社会信用代码" width="130" />-->
    <el-table-column prop="cityName" label="服务城市" width="130" />
    <el-table-column prop="canPickUp" label="接单状态" width="130" #default="scope">
      <template v-if="scope.row.canPickUp == 1"> 接单中 </template>
      <template v-if="scope.row.canPickUp == 0"> 休息中 </template>
    </el-table-column>

    <el-table-column prop="status" label="账号状态" v-slot="scope" width="130">
      <template v-if="scope.row.status == 1"> 冻结 </template>
      <template v-if="scope.row.status == 0"> 正常 </template>
    </el-table-column>
    <el-table-column prop="certificationTime" label="认证时间" width="130" />

    <el-table-column label="操作" width="200">
      <template #default="scope">
        <el-button @click="dj(scope.row)" type="text" size="small" class="action-button" v-if="scope.row.status == 0">冻结</el-button>
        <el-button @click="jd(scope.row)" type="text" size="small" class="action-button" v-if="scope.row.status == 1">恢复</el-button>
        <router-link :to="{path:'/agency/listagency',query:{id:scope.row.id} }">查看</router-link>
      </template>

    </el-table-column>
  </el-table>

  <el-pagination
    v-model:current-page="listagency.pageNum"
    v-model:page-size="listagency.pageSize"
    :page-sizes="[5, 10, 15, 20]"
    layout="total, sizes, prev, pager, next, jumper"
    :total="total"
    @size-change="handleSizeChange"
    @current-change="handleCurrentChange"
  />
</template>

<script setup>

//查看客户列表
import {ref} from "vue";
import {dongjie, getagency} from "@/api/agency/agency";
import {ElMessage} from "element-plus";
import {dong, jie} from "@/api/serveProvider/serveProvider";

const tableData = ref([]);
const total=ref(0)
const listagency=ref({
  id:'',
  pageNum:1,
  pageSize:5,
  name:'',
  phone:'',
  canPickUp:''
})
const handleSizeChange = (val) => {
  listagency.value.pageSize=val
  findall()
}
const handleCurrentChange = (val) => {
  listagency.value.pageNume=val
  findall()
}
function findall() {
  getagency(listagency.value).then((res) => {
    console.log(res)
    tableData.value = res.data.data.list;
    total.value=res.data.data.total;
    console.log(res.data);
  });
}
findall();


// 冻结
function dj(id){
  dong(id).then(res => {
    console.log(res)
    if (res.data.code=200){
      ElMessage.success('冻结成功')
      show()
    }else {
      ElMessage.error(res.data.errorMessage)
    }
  })

}



// 解冻
function jd(id){
  jie(id).then(res => {
    console.log(res)
    if (res.data.code=200){
      ElMessage.success('解冻成功')
      show()
    }else {
      ElMessage.error(res.data.errorMessage)
    }
  })

}


</script>
